var $content_area;
var app = new Vue({
  el: '#app',
  data: function () {
    return {

      treeData: [],
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      filterText: '',

      currentChosenNodeName: "暂无数据",
      currentDataObj: {},
      currentChosenNodeExtendStr : "",

      isLeaf : false,
      showExeDetail: false,

    }
  },

  create() {
    $content_area = $("#content-area");
  },
  mounted() {
    this.loadExpData()
  },
  computed: {
    // currentDataObj: function () {
    //   this.currentChosenNodeExtendStr = this.currentDataObj.extendStr;
    // }
  },
  methods: {

    loadExpData: function () {
      let that = this;
      $.get({
        url: "/api/common/getTree",
        dataType: "json",
        success: function (res) {
          // console.log(resp.data);
          // let res = resp.data;
          if (!res.success) {
            that.showRightMessage(
                that.getSimpleRightMsgObj("title", res.message, "error", false,
                    true));
            return;
          }
          that.treeData = res.data;
        }
      });
    },

    onNodeClick: function (data) {
      // 第一个回调参数是tree data 属性中的对象
      console.log(data);
      this.currentDataObj = data;
      this.currentChosenNodeName = data.name;
      let level = data.level;

      if (level === 4) {
        this.isLeaf = true;
        let mdText = data.extendStr;
        if (!isEmpty(mdText)) {
          this.currentChosenNodeExtendStr = marked(mdText);
        } else {
          this.currentChosenNodeExtendStr = "暂无数据";
        }
      } else {
        this.isLeaf = false;
        let mdText = data.description;
        if (!isEmpty(mdText)) {
          this.currentChosenNodeExtendStr = marked(mdText);
        } else {
          this.currentChosenNodeExtendStr = "暂无数据";
        }
      }
    },

    showTopMessage: function (obj) {
      return (this.$message({
        type: obj.type,
        message: obj.content,
        duration: obj.autoClose ? 6000 : 0,
        showClose: obj.showClose,
      }));
    },

    showSimpleAutoHideTopMessage(type, text) {
      this.showTopMessage({
        type: type,
        content: text,
        autoClose: true,
        showClose: true,
      })
    },

    showRightMessage: function (msgObj) {
      return (this.$notify({
        title: msgObj.title,
        message: msgObj.content,
        type: msgObj.type,
        duration: msgObj.autoClose ? 8000 : 0,
        showClose: msgObj.showClose,
      }));
    },

    getSimpleRightMsgObj(title, msg, type, autoClose, showClose) {
      return {
        title: title,
        content: msg,
        type: type,
        autoClose: autoClose,
        showClose: showClose
      };
    },

  }
});

